﻿import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import "../components"
import "../sampleManager"

Item {

    id: pageAnalysis

    property int currentPage: 0   // 0: 未选择 1: 本机 2: 其它设备文件

    Connections{
        target: mainwindow
        onTabAnalysis:{
            if(expId===-1){
            }else{
                openLocal.expGuid = expId
                openLocal.open()
                currentPage = 1
                equInfo_text.text = expInfo["EquName"] + " | " + expInfo["Ip"]
            }
        }
        onAskForTab:{
            if(mainwindow.mainPage !== 2) return
            mainwindow.permitTab()
        }
    }
    // 样式 =======================================================================

    anchors.fill: parent
    anchors.margins: 15*dp
    Item{                           // 上面的条
        id: layout_top
        height: 40 *dp
        width: parent.width
        Text{
            text: "数据分析"
            font.pixelSize: config.fontsize+4
            font.bold: true
            anchors.verticalCenter: parent.verticalCenter
        }
        Text{
            id: equInfo_text
            text: "第一号设备" + " | " + "192.168.1.183"
            font.pixelSize: config.fontsize-1
            font.bold: true
            x: 90*dp
            color: "#888888"
            visible: currentPage === 1
            anchors.verticalCenter: parent.verticalCenter
            anchors.verticalCenterOffset: 3
        }
        PushButton{
            x: parent.width - 120*dp
            button_border: "#DDDDDD"
            title: "返回"
            visible: currentPage !== 0
            onReleased: {
                // 从数据分析返回时
                if(currentPage === 1){
                    CAnalysis.closeAnalysis("");

                }
                currentPage = 0
            }
        }
        PushButton{
            x: parent.width - 240*dp-20
            button_border: "#DDDDDD"
            title: "导出报告"
            visible: currentPage === 2
            onReleased: {
                CULF.datao()
            }
        }
        PushButton{
            x: parent.width - 360*dp-40
            button_border: "#DDDDDD"
            title: "打印报告"
            visible: currentPage === 2
            onReleased: {

            }
        }
    }
    Item{   // 下侧 切换页面
        id: layout_bottom
        height: parent.height - 50*dp
        width: parent.width
        y: 50*dp

        Item{       // 空状态
            anchors.fill: parent
            visible: currentPage === 0
            Row{
                anchors.centerIn: parent
                anchors.verticalCenterOffset: -60*dp
                spacing: 60*dp
                FileSelectButton{
                    title: "本机文件"
                    tip: "注：仅限wlk格式文件"
                    icon: "qrc:/picture/open_file.png"
                    onReleased: {
                        var res = CWlk.openWlkFile()
                        if(res["ExpGuid"] === undefined){
                            mainwindow.showToast("文件格式不正确", 1)
                            return
                        }else if(res["ExpGuid"] === ""){
                            return
                        }
                        openLocal.expGuid = res["ExpGuid"]
                        openLocal.open()
                        currentPage = 1
                        equInfo_text.text = res["EquName"] + " | " + res["Ip"]
                    }
                }FileSelectButton{
                    title: "其它设备文件"
                    tip: "注：仅限xls或xlsx格式文件"
                    icon: "qrc:/picture/open_device.png"
                    onReleased: {
                        dialog.show()
                    }
                }
            }
        }

        Item{
            anchors.fill: parent
            visible: currentPage === 1
            OpenLocal{
                id: openLocal
                anchors.fill: parent
            }
        }

        Item{
            anchors.fill: parent
            visible: currentPage === 2
            OpenOther{
                id: openOther
                anchors.fill: parent
            }
        }

    }


    Item{      // 测试用数据
        height: 40*dp
        width: 40*dp
        y: 400*dp
        visible: currentPage === 0
        Text{
            text: "测"
            font.pixelSize: 20*dp
            opacity: 0.1
            anchors.centerIn: parent
        }
        MouseArea{
            anchors.fill: parent
            onReleased: {
                var res = CWlk.openWlkFile(true)
                if(res["ExpGuid"] === undefined){
                    mainwindow.showToast("文件格式不正确", 1)
                    return
                }else if(res["ExpGuid"] === ""){
                    return
                }
                openLocal.expGuid = res["ExpGuid"]
                openLocal.open()
                currentPage = 1
                equInfo_text.text = res["EquName"] + " | " + res["Ip"]
            }
        }
    }

    // 定义弹窗
    DialogOther{
        // 按钮的处理
        id: dialog
        onAccept: {
            if(CULF.jy()===0){
                CULF.datain();
                currentPage = 2;
                dialog.close()
            }
        }
        onReject: {

        }
    }
}
